package com.xunyin.modules.mtdouyin.rest;

import com.xunyin.api.ApiResult;
import com.xunyin.common.bean.LocalUser;
import com.xunyin.common.interceptor.AuthCheck;
import com.xunyin.douyin.DouyinConponParam;
import com.xunyin.douyin.DouyinConponService;
import com.xunyin.douyin.result.DouyinCouponVerifyResult;
import com.xunyin.modules.log.AppLog;
import com.xunyin.modules.user.domain.YxUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 抖音团购套餐类controller
 * <p>
 * Created by xunyin
 * CopyRight 讯音云商 https://www.tonetn.com
 */
@Slf4j
@RestController
@Api(value = "共享空间:抖音团购套餐", tags = "共享空间:抖音团购套餐")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ClientDouyinController {

    private final DouyinConponService douyinConponService;

    /**
     * 抖音验券接口
     *
     * @return ApiResult<DianpingPrepareResult>
     */
    @AppLog(value = "抖音验券接口", type = 1)
    @AuthCheck
    @PostMapping("/douyinVerifyCoupon")
    @ApiOperation(value = "抖音验券接口", notes = "抖音验券接口")
    public ApiResult<DouyinCouponVerifyResult> douyinVerifyCoupon(HttpServletRequest request, @RequestBody DouyinConponParam douyinConponParam) {
        // Code、EncryptedData、StoreId、PoiId
        YxUser yxUser = LocalUser.getUser();
        Integer userId = yxUser.getUid().intValue();
        douyinConponParam.setUserId(userId);
        DouyinCouponVerifyResult verifyResult = douyinConponService.frontSubmitVerifyCoupon(douyinConponParam);
        return ApiResult.ok(verifyResult);
    }

}
